package com.longge;

public class MakeGood {

    String str = "";

    public String makeGood(String s) {
        if (s.equals("")) return str;
        StringBuilder sb = new StringBuilder();
        char[] chars = s.toCharArray();
        for (int i = 0; i < chars.length - 1; i++) {
            if (Character.toLowerCase(chars[i]) == Character.toLowerCase(chars[i+1])) {
                if (Character.isUpperCase(chars[i]) && !Character.isUpperCase(chars[i + 1])) {
                    chars[i] = ' ';
                    chars[i + 1] = ' ';
                } else if (!Character.isUpperCase(chars[i]) && Character.isUpperCase(chars[i + 1])) {
                    chars[i] = ' ';
                    chars[i + 1] = ' ';
                }
            }
        }
        for (char aChar : chars) {
            if (aChar != ' ') {
                sb.append(aChar);
            }
        }
        String subStr = sb.toString();
        if (subStr.equals(str)) return str;
        str = subStr;
        return makeGood(subStr);

    }

    public static void main(String[] args) {
        String abBAcC = new MakeGood().makeGood("abBAcC");
        System.out.println(abBAcC);
    }
}
